from appium import webdriver
from appium.webdriver.common.appiumby import By
from time import sleep
def zybcaps():
    desired_caps = {}
    desired_caps['platformName'] = 'Android'
    desired_caps['platformVersion'] = '7'
    desired_caps['deviceName'] = '127.0.0.1:62001'
    desired_caps['app'] = r'D:\apk\zuoyebang.apk'
    desired_caps['appPackage'] = r'com.baidu.homework'
    desired_caps['appActivity'] = r'com.baidu.homework.activity.init.InitActivity'
    desired_caps['noReset'] = False  # False代表重置（重新安装），默认值就是False
    driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
    driver.implicitly_wait(10)
    sleep(3)
    # 点击 同意
    try:
        ele = driver.find_element(By.ID, 'com.baidu.homework:id/iknow_alert_dialog_button2')
    except Exception as e:
        print(e)
    else:
        ele.click()
    # 点击 同意开启
    try:
        ele = driver.find_element(By.ID, 'com.baidu.homework:id/tv_agree_click')
    except Exception as e:
        print(e)
    else:
        ele.click()
    # 点击 允许
    try:
        ele = driver.find_element(By.ID, 'com.android.packageinstaller:id/permission_allow_button')
    except Exception as e:
        print(e)
    else:
        ele.click()
    # 点击 允许
    try:
        ele = driver.find_element(By.ID, 'com.android.packageinstaller:id/permission_allow_button')
    except Exception as e:
        print(e)
    else:
        ele.click()
    sleep(2)
    try:
        ele=driver.find_elements(By.CLASS_NAME, 'android.widget.ImageView')[2]
    except Exception as e:
        print(e)
    else:
        ele.click()
    return driver
if __name__ == '__main__':
    driver = zybcaps()
    driver.find_element(By.ID, 'com.baidu.homework:id/passport_phone_number_input_edit').send_keys('18638933197')
    driver.find_element(By.ID, 'com.baidu.homework:id/passport_password_input_view').send_keys('zuoyebang')
    driver.find_element(By.ID, 'com.baidu.homework:id/tv_phone_enter').click()
    sleep(3)
    driver.quit()

